<?php
require_once 'libs/Config.php';
$Config=new Config();
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="assets/css/base.css" type="text/css" />
    <title>获取授权URL</title>
</head>
<body>
<div class="input-container">
    <label>开发者应用的AppID：</label>
    <input type="text" id="app_id" value="<?php echo $Config->app_id;?>">
</div>
<div class="input-container">
    <label>回调页面地址：</label>
    <input type="text" id="redirect_uri" value="<?php echo $Config->redirect_uri;?>" style="min-width: 350px;">
</div>
<input type="button" value="获取授权URL" onclick="getAuthUrl();">
<div id="auth_url" class="input-container" style="display: none;">
    <label>授权URL：</label>
    <a href="xxx">xxx</a>
    <span>3s后跳转...</span>
</div>
</body>
<script type="text/javascript">
    //获取授权地址，并在3s后跳转
    function getAuthUrl() {
        let obj1=document.querySelector("#app_id");
        let obj2=document.querySelector("#redirect_uri");
        let app_id=obj1.value;
        let redirect_uri=encodeURI(obj2.value);
        let authUrl=`https://openauth.alipay.com/oauth2/appToAppAuth.htm?app_id=${app_id}&redirect_uri=${redirect_uri}`;

        let obj3=document.querySelector("#auth_url");
        let obj4=obj3.querySelector("a");
        obj4.href=authUrl;
        obj4.innerText=authUrl;
        obj3.style.display='block';
        setTimeout(()=>{
            window.location.href=authUrl;
        },3000);
    }
</script>
</html>